//
//  WBResponse.m
//  ＷebServiceDemo
//
//  Created by wulanzhou on 16/3/7.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "WBResponse.h"
#import "XmlParseHelper.h"

@implementation WBResponse

- (id)json{
    if (self.content&&[self.content isKindOfClass:[NSString class]]&&[self.content length]>0) {
        return [NSJSONSerialization JSONObjectWithData:[self.content dataUsingEncoding:NSUTF8StringEncoding] options:1 error:nil];
    }
    return nil;
}

- (instancetype)initWithDictionary:(id)response error:(NSError *)error{
    
    if (self=[super init]) {
        
        if (error) {
            self.errMsg  = @"服务异常,请稍后重试";
            self.success    = NO;
        }else{
            if (response) {
                if ([response isKindOfClass:[NSData class]]) {
                   
                    self.xml = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];

                    NSString *repStr = [self.xml stringByReplacingOccurrencesOfString:@"xmlns=\"http://webservices.energyspace\"" withString:@""];

                    XmlParseHelper *parse = [[XmlParseHelper alloc] initWithData:repStr];
                    //self.content = [parse soapXmlSelectSingleNode:[NSString stringWithFormat:@"//%@Return"],args.soapBody.methodName];
                    
                    
                }else if ([response isKindOfClass:[NSDictionary class]]){
                    
                }
                
            }else{
               
                self.errMsg  = @"返回数据为nil";
                self.success    = NO;
                
            }
        }
    }
    return self;
}

@end
